package it.poste.il.compensatore.entities;

import java.sql.Date;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.ManyToOne;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

@Entity
@Table(name="messages")
public class Message extends BaseEntity {

	private static final long serialVersionUID = -5272430311150598722L;

	private Date timestamp;
	
	private int type;
	
	@OneToOne(fetch=FetchType.LAZY, cascade=CascadeType.ALL, mappedBy="message", targetEntity=MessageBody.class)
	private MessageBody messageBodys;
	
	@ManyToOne(fetch=FetchType.LAZY)
	private Operation operationId;

	@ManyToOne(fetch=FetchType.LAZY)
	private MessageStatus statusId;
	
	@ManyToOne(fetch=FetchType.LAZY)
	private SDPRequest sdpRequestId;

	public Date getTimestamp() {
		return timestamp;
	}

	public void setTimestamp(Date timestamp) {
		this.timestamp = timestamp;
	}
	
	public int getType() {
		return type;
	}

	public void setType(int type) {
		this.type = type;
	}
	
	public Operation getOperationId() {
		return operationId;
	}
	
	public void setOperationId(Operation operationId) {
		this.operationId = operationId;
	}
	
	public MessageStatus getStatusId() {
		return statusId;
	}
	
	public void setStatusId(MessageStatus i) {
		this.statusId = i;
	}
	
	public SDPRequest getSdpRequestId() {
		return sdpRequestId;
	}

	public void setSdpRequestId(SDPRequest sdpRequestId) {
		this.sdpRequestId = sdpRequestId;
	}

	public MessageBody getMessageBodys() {
		return messageBodys;
	}

	public void setMessageBodys(MessageBody messageBodys) {
		this.messageBodys = messageBodys;
	}
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((getId() == null) ? 0 : getId().hashCode());
		result = prime * result
				+ ((operationId == null) ? 0 : operationId.hashCode());
		result = prime * result
				+ ((statusId == null) ? 0 : statusId.hashCode());
		result = prime * result
				+ ((timestamp == null) ? 0 : timestamp.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Message other = (Message) obj;
		if (getId() == null) {
			if (other.getId() != null)
				return false;
		} else if (!getId().equals(other.getId()))
			return false;
		if (operationId == null) {
			if (other.operationId != null)
				return false;
		} else if (!operationId.equals(other.operationId))
			return false;
		if (statusId == null) {
			if (other.statusId != null)
				return false;
		} else if (!statusId.equals(other.statusId))
			return false;
		if (timestamp == null) {
			if (other.timestamp != null)
				return false;
		} else if (!timestamp.equals(other.timestamp))
			return false;
		return true;
	}

	@Override
	public String toString() {
		return this.getClass().getName() + " [type=" + getType() + ", id=" + getId() + ", operationId="
				+ operationId + ", statusId=" + statusId + "]";
	}
	
}